package com.second.app.thread.synchroized.deadlock;


public class Run {

    private static Object res01 = new Object();

    private static Object res02 = new Object();

    public static void main(String[] args) {


        new Thread(() -> {
            synchronized (res01) {
                System.out.println(Thread.currentThread()+" 获得 res01");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            System.out.println(Thread.currentThread()+"waiting get res02");
            synchronized (res02) {
                System.out.println(Thread.currentThread()+" 获得 res02");
            }
        }, "线程01").start();

        new Thread(() -> {
            synchronized (res02) {
                System.out.println(Thread.currentThread()+" 获得 res02");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread()+"waiting get res01");
            synchronized (res01) {
                System.out.println(Thread.currentThread()+" 获得 res01");
            }
        }, "线程02").start();

    }
}
